package cn.circle.mobile.util;

import net.sf.json.JSONException;
import net.sf.json.JSONObject;

import cn.circle.system.model.SysCustomer;

/**
 * 拉取用户资料
 * 
 * @author  
 * @param
 * @param   
 * @Date 
 */

public class GetUserInfoUtil {

	public static SysCustomer getUserInfo(String openId,String access_token) {
		SysCustomer c = null;
		String requestUrl = WeChatProperties.GET_USER_INFO_URL.replace("ACCESS_TOKEN",access_token).replace("OPENID",
				openId);
		JSONObject jsonObject = ToeknUtil.HttpRequest(requestUrl, "GET", null);
		// 如果请求成功
		if (null != jsonObject) {
			try {
//				c = new SysCustomer();
//				c.setSubScribe(jsonObject.getInt("subscribe"));
//				c.setOpenId(jsonObject.getString("openid"));
//				c.setNickName(jsonObject.getString("nickname"));
//				c.setSex(jsonObject.getInt("sex"));
//				c.setLanguage(jsonObject.getString("language"));
//				c.setCity(jsonObject.getString("city"));
//				c.setProvince(jsonObject.getString("province"));
//				c.setCountry(jsonObject.getString("country"));
//				c.setHeadImgurl(jsonObject.getString("headimgurl"));
//				//c.setSubScribeTime(jsonObject.get("subscribe_time"));
//				c.setRemark(jsonObject.getString("remark"));
//				c.setGroupId(jsonObject.getInt("groupid"));

			} catch (JSONException e) {
				c = null;
				// 获取用户信息失败
//				String result = String.format("获取用户信息失败 errcode:%s errmsg:%s", jsonObject.getInt("errcode"),
//						jsonObject.getString("errmsg"));
//				System.out.println(result);
			}
		}
		return c;
	}

}
